import Vue from 'vue'
import VueRouter from 'vue-router'
import { setRouterAuth } from './router.auth'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}
const routes = [
  {
    path: '/',
    component: () => import('@/components/TheHead'),
    children: [
      {
        path: '/',
        name: 'home',
        component: () => import('../views/HomeView.vue')
      },

      {
        path: '/interviewArticle',
        name: 'interviewArticle',
        component: () => import('../views/interview-article')
      },
      {
        path: '/articleDetail/:id',
        name: 'article',
        component: () => import('../views/article')
      },
      {
        path: '/selfcenter',
        component: () => import('../views/self-center'),
        children: [
          {
            path: '/',
            redirect: 'release'
          },
          {
            path: 'release',
            name: 'release',
            component: () =>
              import('../views/self-center/components/release.vue')
          },
          {
            path: 'editseifinfo',
            name: 'editseifinfo',
            component: () =>
              import('../views/self-center/components/edit-self-info.vue')
          },
          {
            path: 'collectarticle',
            name: 'collectarticle',
            component: () =>
              import('../views/self-center/components/collect-article.vue')
          },
          {
            path: 'collectquestion',
            name: 'collectquestion',
            component: () =>
              import('../views/self-center/components/collect-question.vue')
          }
        ]
      },
      {
        path: '/questions',
        name: 'questions',
        component: () => import('../views/question/')
      },
      {
        path: '/questionsDetail/:id',
        name: 'questionsDetail',
        component: () => import('../views/question-detail')
      }
    ]
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/register')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login')
  },
  {
    path: '/editor',
    name: 'editor',
    component: () => import('../views/editor')
  },
  {
    path: '/questionEditor',
    name: 'questionEditor',
    component: () => import('../views/question-editor')
  },
  {
    path: "/questionEditor",
    name: "questionEditor",
    component: () => import("../views/question-editor"),
  },
  // {
  //   path: "/404",
  //   name: "notFound",
  //   component: () => import("@/views/page-404"),
  // },
  {
    path: '*', // 此处需特别注意置于最底部
    component: () => import('@/views/page-404')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach = setRouterAuth(router)

export default router
